import { useReducer } from "react";

/*
 * @Author: Wxx
 * @Date: 2022-02-22 17:15:07
 * @LastEditors: Wxx
 * @LastEditTime: 2022-02-22 17:24:39
 * @Description:
 */
const add = "ADD";
const minus = "MINUS";
const reducers = (prevState, action) => {
  let newState = { ...prevState };
  switch (action.type) {
    case add:
      newState.count++;
      return newState;
    case minus:
      newState.count--;
      return newState;
    default:
      return prevState;
  }
};
const initstate = {
  count: 0,
};
export default function App() {
  const [state, dispatch] = useReducer(reducers, initstate);

  return (
    <div>
      <button
        style={{ width: 200, height: 60, fontSize: 32, marginRight: 40 }}
        onClick={() => {
          dispatch({
            type: add,
          });
        }}
      >
        +
      </button>
      {state.count}
      <button
        style={{ width: 200, height: 60, fontSize: 32, marginLeft: 40 }}
        onClick={() => {
          dispatch({
            type: minus,
          });
        }}
      >
        -
      </button>
    </div>
  );
}
